// 渲染部门编制下拉
function showSel() {
    $.ajax({
        url: '/organization/showsel_branch',
        success: (res) => {
            $('#sel_1').html('<option value="" selected disabled class="sel_none">部门类别名称</option>');
            $(res.data).each((index, item) => {
                $('#sel_1').append(`    
            <option value="${item.b_name}">${item.b_name}</option>`);
            })
        }
    })
}

// 渲染班级编制下拉
function showClassSel() {
    $.ajax({
        url: '/class/showsel_department',
        success: (res) => {
            $('#sel_1').html('<option value="" selected disabled class="sel_none">学院类别名称</option>');
            $(res.data).each((index, item) => {
                $('#sel_1').append(`    
            <option value="${item.d_name}">${item.d_name}</option>`);
            })
        }
    })
}
let bVal = ''

$('#sel_1').click(function() {
        bVal = $(this).val();
    })
    // 给下拉添加点击事件，获取val值然后渲染表的内容
function clickSel() {
    $.ajax({
        url: '/organization/preparation',
        method: 'post',
        data: {
            b_name: $('#sel_1').val()
        },
        success: (res) => {
            let totalNum1 = 0
            let totalNum2 = 0
            let totalNum3 = 0
            let totalNum4 = 0
            let totalNum5 = 0
            let totalNum6 = 0
            let totalNum7 = 0
            let totalNum8 = 0
            let totalNum9 = 0
            let totalNum10 = 0
            let totalNum11 = 0
            let totalNum12 = 0
            $('#table_left tbody').html('');
            $('#table_right tbody').html('');
            $(res.data).each((index, item) => {
                $('#table_left tbody').append(`    
                    <tr>
                        <th class="table_color">
                            <div class="checkbox">
                                <label>
                            <input type="checkbox" value="option1" aria-label="...">
                            </label>
                            </div>
                        </th>
                        <th>${item.p_id}</th>
                        <th>${item.p_name}</th>
                    </tr>`);
            })
            $('#table_left tbody').append(`   
                <tr>
                    <th class="table_color">
                        <div class="checkbox">
                            <label>
                        <input type="checkbox" value="option1" aria-label="...">
                        </label>
                        </div>
                    </th>
                    <th colspan="2">合计人数</th>
                </tr>`)
            for (let i = 0; i < res.data.length; i++) {
                $('#table_right tbody').append(`    
                    <tr>
                        <th>${res.data[i].p_num+1}</th>
                        <th>${res.data[i].p_num+1}</th>
                        <th>${res.data[i].p_num+2}</th>
                        <th>${res.data[i].p_num+2}</th>
                        <th>${res.data[i].p_num+1}</th>
                        <th>${res.data[i].p_num+1}</th>
                        <th>${res.data[i].p_num+1}</th>
                        <th>${res.data[i].p_num+2}</th>
                        <th>${res.data[i].p_num+2}</th>
                        <th>${res.data[i].p_num}</th>
                        <th>${res.data[i].p_num}</th>
                        <th>${res.data[i].p_num}</th>
                    </tr>`);
                totalNum1 += res.data[i].p_num + 1;
                totalNum2 += res.data[i].p_num + 1;
                totalNum3 += res.data[i].p_num + 2;
                totalNum4 += res.data[i].p_num + 2;
                totalNum5 += res.data[i].p_num + 1;
                totalNum6 += res.data[i].p_num + 1;
                totalNum7 += res.data[i].p_num + 1;
                totalNum8 += res.data[i].p_num + 2;
                totalNum9 += res.data[i].p_num + 2;
                totalNum10 += res.data[i].p_num;
                totalNum11 += res.data[i].p_num;
                totalNum12 += res.data[i].p_num;
            }
            $('#table_right tbody').append(` 
                    <tr>
                        <th>${totalNum1}</th>
                        <th>${totalNum2}</th>
                        <th>${totalNum3}</th>
                        <th>${totalNum4}</th>
                        <th>${totalNum5}</th>
                        <th>${totalNum6}</th>
                        <th>${totalNum7}</th>
                        <th>${totalNum8}</th>
                        <th>${totalNum9}</th>
                        <th>${totalNum10}</th>
                        <th>${totalNum11}</th>
                        <th>${totalNum12}</th>
                    </tr>
                    `)
        }
    })
}
let arr = []

function clickSel2() {
    $.ajax({
        url: '/class/preparation_left',
        method: 'post',
        data: {
            d_name: $('#sel_1').val()
        },
        success: (res) => {
            console.log(res.data);
            $('#table_left tbody').html('');
            $('#table_right tbody').html('');
            $(res.data).each((index, item) => {
                $('#table_left tbody').append(`    
                    <tr>
                        <th class="table_color">
                            <div class="checkbox">
                                <label>
                            <input type="checkbox" value="option1" aria-label="...">
                            </label>
                            </div>
                        </th>
                        <th>${item.m_id}</th>
                        <th>${item.m_name}</th>
                    </tr>`);
                $('#table_right tbody').append(`    
                    <tr>                    
                        <th>12</th>
                        <th>12</th>
                        <th>12</th>
                        <th>12</th>
                        <th>12</th>
                        <th>12</th>
                        <th>12</th>
                        <th>12</th>
                        <th>12</th>
                        <th>12</th>
                        <th>12</th>
                        <th>12</th>                
                    </tr>`);
            })
            $('#table_left tbody').append(`   
                <tr>
                    <th class="table_color">
                        <div class="checkbox">
                            <label>
                        <input type="checkbox" value="option1" aria-label="...">
                        </label>
                        </div>
                    </th>
                    <th colspan="2">合计班级数量</th>
                </tr>`);
            $('#table_right tbody').append(` 
                <tr>
                    <th>${12*res.total}</th>
                    <th>${12*res.total}</th>
                    <th>${12*res.total}</th>
                    <th>${12*res.total}</th>
                    <th>${12*res.total}</th>
                    <th>${12*res.total}</th>
                    <th>${12*res.total}</th>
                    <th>${12*res.total}</th>
                    <th>${12*res.total}</th>
                    <th>${12*res.total}</th>
                    <th>${12*res.total}</th>
                    <th>${12*res.total}</th>
                </tr>
                `)
        }
    })
}